package com.springcloud.test;

import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;


/**
 * @Desc: ----------------
 * @CLASS_NAME: UploadService
 * ----------------
 * @Author: jovi
 * ----------------
 * @Date: 2020-03-24 17:15
 */
@FeignClient(value = "feign-upload-server", configuration = UploadService.MultipartSupportConfig.class)
public interface UploadService {

    /**
     * 上传
     *
     * @param file
     * @return
     */
    @PostMapping(value = "/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    String handleFileUpload(@RequestPart(value = "file") MultipartFile file);


    class MultipartSupportConfig {

        @Bean
        public Encoder feignFormEncoder() {
            return new SpringFormEncoder();
        }
    }
}
